"""DreamLife URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from django.conf.urls import handler404, url
from django.conf import settings

# 导入主项目的视图函数用于渲染初始index页面
from . import views as main_views
from django.shortcuts import render
from django.views import static

# 定义一个处理404错误的视图函数
def custom_page_not_found_view(request, exception):
    return render(request, '404.html', status=404)  # 渲染自定义的404页面模板


# 路由组
urlpatterns = [
    path('user/', include("user.urls")),
    path('blog/', include("blog.urls")),
    path('comment/', include("comment.urls")),
    path('admin/', admin.site.urls),
    # path('captcha', include('captcha.urls'))
    path('', main_views.index, name='index'),  # 设置空路径为初始页面
    path('index', main_views.index, name='index'),  # 设置index为初始页面
    path('developers/', main_views.developersView, name='developers'),
    path('feedback/', main_views.feedbackView, name='feedback'),  # 注册 feedback 的 URL
    path('document/', main_views.documentView, name='document'),
    path('submit_feedback/', main_views.submit_feedback, name='submit_feedback'),  # 处理反馈表单提交的 URL
    url(r'^static/(?P<path>.*)$', static.serve, {'document_root': settings.STATIC_ROOT}, name='static'),
    ]

# 设置404页面处理器
handler404 = 'DreamLife.urls.custom_page_not_found_view'
